<?php
namespace app\pub;

/**
 * OpenAnts.com
 */
/**
 * 生成唯一订单号
 */
class  Ants4PHP
{
    public static function ant_order()
    {
        $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
        $orderSn = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
        return $orderSn;
    }

    /**
     * UUID 生成工具
     */
    public static function ant_uuid()
    {
        $chars = md5(uniqid(mt_rand(), true));
        $uuid = substr($chars, 0, 8) . '-'
            . substr($chars, 8, 4) . '-'
            . substr($chars, 12, 4) . '-'
            . substr($chars, 16, 4) . '-'
            . substr($chars, 20, 12);
        return $uuid;
    }

    /**
     * 返回 json 值
     * @param int $code
     * @param null $msg
     * @param null $data
     */
    public static function ant_return_json($code = 0, $msg = '', $data = '')
    {
        $ret = array('code' => $code, 'msg' => $msg, 'data' => $data);
        exit(json_encode($ret));
    }

    /**
     * 删除空格，清楚文件中的空格和空字符串
     */
    public static function ant_remove_null($str)
    {
        $oldchar = array(" ", "　", "\t", "\n", "\r");
        $newchar = array("", "", "", "", "");
        return str_replace($oldchar, $newchar, $str);
    }

    /**
     * ASCII排序
     */
//自定义ascii排序
    public static function ant_ASCII($params = array())
    {
        if (!empty($params)) {
            $p = ksort($params);
            if ($p) {
                $str = '';
                foreach ($params as $k => $val) {
                    $str .= $k . '=' . $val . '&';
                }
                $strs = rtrim($str, '&');
                return $strs;
            }
        }
        return '参数错误';
    }
}
